<%--
  Created by IntelliJ IDEA.
  User: 97990
  Date: 2022/7/19
  Time: 18:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <jsp:include page="/common/head.jsp"></jsp:include>
    <title>修改书籍</title>
</head>
<body>
<jsp:include page="/common/nav.jsp"></jsp:include>
<form class="form-horizontal">
    <div class="form-group">
        <label class="col-sm-2 control-label">图书名称:</label>
        <div class="col-sm-4">
            <input type="text" id="bookName" class="form-control"  placeholder="请输入图书名称">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">图书价格:</label>
        <div class="col-sm-4">
            <input type="text" id="bookPrice" class="form-control"  placeholder="请输入图书价格">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" class="btn btn-primary" onclick="updateBook();"><span class="glyphicon glyphicon-ok"></span>修改</button>
            <button type="reset" class="btn btn-default"><i class="glyphicon glyphicon-refresh"></i>重置</button>
        </div>
    </div>
</form>

<jsp:include page="/common/script.jsp"></jsp:include>
<script>
    var v_id = '${param.id}';
    $(function (){
        initFind();
    })

    function initFind(){
        $.ajax({
            type:"post",
            url:"/book/findBook.do",
            data:{"id":v_id},
            success:function (res){
                if (res.code ==200){
                    var v_book = res.data;
                    $("#bookName").val(v_book.bookName);
                    $("#bookPrice").val(v_book.bookPrice);
                }
            }
        })
    }

    function updateBook(){
        var v_param = {};
        v_param.id = v_id;
        v_param.bookName = $("#bookName").val();
        v_param.bookPrice = $("#bookPrice").val();
        $.ajax({
            type:"post",
            url:"/book/update.do",
            data:v_param,
            success:function (res){
                if (res.code == 200){
                    location.href = "/book/toIndex.do";
                }
            }
        })
    }
</script>
</body>
</html>
